package com.example.test;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * TODO: 这里要写注释的!
 */
public class PrintQueue {
    private final Lock queueLock= new ReentrantLock();
    public void printJob(Object document){
        queueLock.lock();
        try{
            long duration= (long) (Math.random()*10000);
            System.out.printf(Thread.currentThread().getName()+": PrintQueue: printing a Job during "+(duration/1000)+" seconds.\n");
            Thread.sleep(duration);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            queueLock.unlock();
        }
    }
}
